#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxCoins(vector<int>& piles) {
        int n = piles.size();
        ranges::sort(piles, [](int a, int b) {
            return a > b;
            });
        int res = 0;
        for (int i = 0, j = 1; i < n / 3; i++, j += 2)
        {
            res += piles[j];
        }
        return res;
    }
};